﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Text;

namespace Jy123.Web.home
{
    public partial class AddBlog : System.Web.UI.Page
    {
        private int userID;//暂用用户ID，写死，到时候用COOKIE替换过来
        
        protected void Page_Load(object sender, EventArgs e)
        {
            string strUserIdFromCookie = Common.Cookie.getCookie("UserID");
            if (string.IsNullOrEmpty(strUserIdFromCookie))
            {
                Response.Redirect("/");
            }
            userID = int.Parse(strUserIdFromCookie);

            //以下暂时别删
            //StringBuilder indexHtml = new StringBuilder(Cache["user_blog"].ToString());
            ////头部、底部、左侧用户命令菜单
            //indexHtml = indexHtml.Replace("$Header$", Cache["user_header"].ToString());
            ////indexHtml = indexHtml.Replace("$Footer$", Cache["user_footer"].ToString());
            //indexHtml = indexHtml.Replace("$LeftUserCmd$", Cache["user_navigation_down"].ToString());
            //indexHtml = indexHtml.Replace("$LeftUserFriendAdd$", Cache["user_friendadd"].ToString());
            ////统计站内信数量
            //Jy123.BLL.User.Letter bllLetter = new Jy123.BLL.User.Letter();
            //int newLetterCount = bllLetter.CountNewLetter(3);
            ////BLL.User_LetterInbox bllInbox = new Jy123.BLL.User_LetterInbox();
            ////bllInbox.GetList("FUser = '" + userID + "'");
            //indexHtml = indexHtml.Replace("$NewMsg$", newLetterCount.ToString());
            ////Response.Write(indexHtml.ToString());
            
        }

        protected void editorFormBtn_Click(object sender, EventArgs e)
        {
            //提交新日志
            Jy123.Model.User_Blog mblog = new Jy123.Model.User_Blog();
            Jy123.BLL.User_Blog bllBlog = new Jy123.BLL.User_Blog();
            mblog.FUser = userID;
            mblog.Title = Request.Form["title"];
            mblog.BlogContent = Request.Form["content"];
            mblog.Privacy = int.Parse(Request.Form["blogControl"]);
            mblog.Comments = 0;
            mblog.IsLock = false;
            mblog.isRec = 0;
            mblog.LastModTime = DateTime.Now;
            mblog.PostIP = Common.Public.GetClientIP();
            mblog.PostTime = DateTime.Now;
            int addnewID =bllBlog.Add(mblog);
            if (addnewID> 0)
            {
                //加入动态
                Jy123.Model.User_Main mUserForState = new Jy123.Model.User_Main();
                Jy123.BLL.User_Main bllUserForState = new Jy123.BLL.User_Main();
                mUserForState = bllUserForState.GetModel(userID);
                Jy123.Model.User_Blog mBlogState = new Jy123.Model.User_Blog();
                Jy123.BLL.User_Blog bllBlogState = new Jy123.BLL.User_Blog();
                mBlogState = bllBlogState.GetModel(addnewID);
                new Jy123.BLL.Public.State().CreateBlogState(mUserForState,mBlogState);
                //加入动态
                Response.Redirect("BlogList_My.aspx");
            }
            else
            {
                Response.Write("javascript:$.moonbox.error('失败');");
            }
        }
    }
}
